<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <form onsubmit="return false" id=login>
        账号：<input type="text" id="username" placeholder="请输入你的账号"> <br>
        密码：<input type="password" id="password" placeholder="请输入你的密码"> <br>
        <input type="submit" value="登录" onclick=login()>
    </form>

    <script>
        function login() {
            var username = document.forms["login"]["username"].value;
            var password = document.forms["login"]["password"].value;
            var msg = {};
            msg.username = username;
            msg.password = password;
            var myJSON = JSON.stringify(msg);
            console.log(myJSON);
            var xmlhttp = new XMLHttpRequest();
            xmlhttp.open("POST", "/login", true);
            xmlhttp.send(myJSON);

            console.log(xmlhttp.status);
        }

    </script>
</body>

</html>